<?php

use think\migration\Seeder;
use think\Db;

class TalkSeeder extends Seeder
{

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * http://docs.phinx.org/en/latest/seeding.html
     */
    public function run()
    {
        for ($i = 0; $i <= 100; $i++) {
            $address = new \app\admin\model\TalkModel();
            $address->save($this->faker());
        }
    }

    public function faker()
    {
        $faker = Faker\Factory::create('zh_CN');
        $type = mt_rand(0,2);
        $users = \api\user\model\UserModel::where('type',$type)->column('id');
        $type1 = mt_rand(0,2);
        if ($type1 == 1){
            $talk_coin = 0;
        }else{
            $talk_coin = mt_rand(1,100);
        }
        if ($type1 == 3){
            $read_time = time();
        }else{
            $read_time = 0;
        }

        return [
            'title' => $faker->sentence(),
            'type'=> $type,
            'user_id'=> $faker->randomElement($users),
            'type1' => mt_rand(0,2),
            'talk_coin' => $talk_coin,
            'content' => $faker->text(),
            'read_time'=> $read_time,
            'praise_num' => mt_rand(1,100),
            'buy_num' => mt_rand(1,100),
            'read_num' => mt_rand(1,100),
        ];
    }
}